<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!--<link rel="shortcut icon" href="/favicon.ico">
    <link rel="apple-touch-icon" href="/apple-touch-icon.png">-->
    <title>{{ title }}</title>
    <link rel="stylesheet" href="/static/editor.css">
    {% block head %}{% endblock %}
  </head>
  <body{% if pagename %} class="{{ pagename }}-body"{% endif %}>

    <div class="editor-chrome">
      <form method="POST" id="save-content-form"
        {% if is_owner %}
          action="/save/{{ prototype.key }}"
        {% else %}
          action="/fork/{{ prototype.key }}"
        {% endif %}
        >
        <input type="hidden" name="continue" value="{{ continue }}">
        <textarea id="save-content" name="content"
          style="display:none">{{ prototype.content }}</textarea>
        <div class="editor-chrome-header">
          <h1>
            <a href="/">codebin</a>
            {% if is_owner %}
              <input name="title" id="save-content-title"
                value="{{ prototype.title }}">
            {% else %}
              <span id="view-content-title">{{ prototype.title }}</span>
              <input type="submit" value="Fork →">
              <strong id="save-content-forkwarn">
                You're viewing someone else's prototype.
                Fork to make changes.
              </strong>
            {% endif %}
          </h1>

          {% if sample_templates %}
            <div id="editor-load-template" class="menu-button-container">
              <button id="editor-load-template-btn"
                class="menu-button">+Template</button>
              <ul class="menu-button-menu">
                {% for template in sample_templates %}
                  <li data-template-url="{{ template.url }}" class="menu-item">
                    {{ template.name }}
                  </li>
                {% endfor %}
                <li>
                  <label for="editor-load-template-url">URL:</label>
                  <input type="text" id="editor-load-template-url">
                  <button type="button" id="editor-load-template-url-btn"
                    >Load</button>
                </li>
              </ul>
            </div>
          {% endif %}

          <div class="editor-chrome-header-links">
            {% if is_owner %}
              <span id="save-content-ts"></span>
              <input id="save-content-btn" type="submit" value="Save">
            {% endif %}

            {% if prototype %}
              <a href="/render/{{ prototype.key.id }}" target="_blank">view→</a>
            {% endif %}

            {% if user %}
              <a href="/mine">{{ user_nickname }}</a>
              <a href="{{ logout_url }}">Sign out</a>
            {% else %}
              <a href="{{ login_url }}">Sign in</a>
            {% endif %}
          </div>
        </div>
      </form>
      {% if pagename %}<div class="{{ pagename }}-content">{% endif %}
      {% block body %}{% endblock %}
      {% if pagename %}</div>{% endif %}
    </div>

    {% if is_production %}
      <script>
        var _gaq = [['_setAccount', 'UA-21455401-1'], ['_trackPageview']];
        (function(d, t) {
          var g = d.createElement(t),
              s = d.getElementsByTagName(t)[0];
          g.async = true;
          g.src = ('https:' == location.protocol ? 'https://ssl' :
              'http://www') + '.google-analytics.com/ga.js';
          s.parentNode.insertBefore(g, s);
        })(document, 'script');
     </script>
   {% endif %}
  </body>
</html>

